<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>解决父子元素间的塌陷问题</title>
    <style>
        .con {
            float: left;
            width: 33.333333%;
            height: 500px;
            box-sizing: border-box;
            border: 1px solid red;
        }

        .block {
            width: 100%;
            height: 100px;
            background-color: magenta;
        }

        .parent {
            width: 80%;
            height: 100px;
            margin: 0 auto;
            background-color: pink;
            margin-top: 100px;
        }

        .son {
            width: 50%;
            height: 50px;
            margin: 0 auto;
            background-color: cyan;
            margin-top: 50px;
        }
    </style>
</head>
<body>
    <div class="con">
        <div class="block"></div>
        <!-- 添加边框或内边距 -->
        <div class="parent" style="border: 1px solid black;">
        <!-- <div class="parent" style="padding: 1px;"> -->
            <div class="son"></div>
        </div>
    </div>
    <div class="con">
        <div class="block"></div>
        <!-- 触发BFC -->
        <div class="parent" style="overflow: hidden;">
            <div class="son"></div>
        </div>
    </div>
    <div class="con">
        <div class="block"></div>
        <!-- 使子元素脱离标准流：绝对定位或浮动 -->
        <div class="parent" style="position: relative;">
            <div class="son" style="position: absolute"></div>
            <!-- <div class="son" style="float: left;"></div> -->
        </div>
    </div>
</body>
</html>